package com.dianrui.operation.adapter;

import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.dianrui.operation.R;
import com.dianrui.operation.util.GlideUtil;


import java.util.List;

import uk.co.senab.photoview.PhotoView;


/**
 *图片的轮播图的适配器
 */

public class BigImagePagerAdapter extends PagerAdapter {

    private List<String> list;
    private Activity context;
    private ImageView iv_pic;

    public BigImagePagerAdapter(Activity context) {
        this.context = context;
    }

    public void updata(List<String> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (list == null) {
            return 0;
        }

        return list.size();

    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;


    }


    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        View view = View.inflate(context, R.layout.item_big_img, null);
        iv_pic = (PhotoView) view.findViewById(R.id.item_big_img_iv_pic);

        GlideUtil.loadImageView(context, list.get(position), iv_pic);


        iv_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClickLinsenter.click();
            }
        });

        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //super.destroyItem(container, position, object);
    }

    private OnItemClickLinsenter itemClickLinsenter;

    public interface OnItemClickLinsenter {
        void click();
    }

    public void setOnItemClickLinsenter(OnItemClickLinsenter linsenter) {
        this.itemClickLinsenter = linsenter;
    }
}
